package com.lagou;

import org.apache.catalina.LifecycleException;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.startup.Tomcat;

import javax.servlet.ServletException;
import java.io.File;

/**
 * @author mcl
 * @date 2021/7/5 2:26 下午
 * @description
 */
public class SpringApplication {
    private static final int PORT = 8085;
    private static final String WEB_APP_PATH = "src/main";

    public static void run() throws LifecycleException, ServletException {
        System.out.println("tomcat start...");

        Tomcat tomcat = new Tomcat();
        tomcat.setPort(PORT);
        //添加webapp
        //webapp禁止重载入
        StandardContext myCtx = (StandardContext) tomcat.addWebapp("", new File(WEB_APP_PATH).getAbsolutePath());

        tomcat.start();
        System.out.println("tomcat started...");
        tomcat.getServer().await();
    }
}
